BRKs (BRX Knowledge Representations) are the fundamental building blocks of the BRX platform. They represent reusable AI components that can be composed together to build complex applications.
A BRK is a prompt with the ability to include variables and other BRKs as dependencies with recursion. Think of it as a function in programming - it takes inputs, processes them, and produces outputs. However, instead of executing code, a BRK processes natural language and interacts with LLMs.Key characteristics of BRKs:
Reusable: Create once, use anywhere
Composable: BRKs can include other BRKs as dependencies
Parameterized: Accept input variables that can be customized at runtime
Versioned: Track changes and maintain compatibility
Shareable: Can be shared with other users and teams
BRKs can be created through the BRX platform UI or programmatically using the BRX API. Here’s an example of creating a BRK using the Node.js SDK:
Copy
Ask AI
import BRX, { BRK } from 'brx-node';// Initialize the BRX clientconst brx = new BRX('your-api-key');// Create a new BRKconst modifyRequest = { modifyBrxMode: 'CREATE', brx: { brxId: 'unique-brx-id', brxName: 'My First BRK', description: 'A simple BRK that does something useful', prompt: { prompt: new Map([ ['main', 'This is the main prompt template with {{variable}}'] ]) }, processParams: { processType: 0 // Standard processing }, dependantBrxIds: new Map([ ['main_brx_entry_schema', 'unique-brx-id'] ]) }, schema: { schemaFields: new Map([ ['variable', { fieldValueDataType: 'string', fieldValue: '' }] ]), brxName: 'My First BRK', brxId: 'unique-brx-id' }};// Send the create requestconst result = await brx.create(modifyRequest);
Once a BRK is created, you can use it by fetching its schema and providing input values:
Copy
Ask AI
import BRX, { BRK } from 'brx-node';const brx = new BRX('your-api-key');// Fetch the BRK Schema with a BRK IDconst myBrkSchema = await brx.get('unique-brx-id');// Initialize the BRK using the schemaconst myBrk = new BRK(myBrkSchema);// Add inputsmyBrk.input['variable'] = 'Some input value';// Run the BRKconst result = await brx.run(myBrk);console.log(result);
One of the most powerful features of BRKs is the ability to include other BRKs as dependencies. This allows you to build complex AI applications by composing simpler components.For example, you might have:
A BRK that extracts key information from a text
A BRK that summarizes information
A BRK that formats the summary in a specific way
You can compose these together by making the summarization BRK depend on the extraction BRK, and the formatting BRK depend on the summarization BRK.When you run the formatting BRK, it will automatically run the summarization BRK, which will in turn run the extraction BRK. The output of each BRK is passed to the next one in the chain.